package com.loveprogrammer.lowercode.dna.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.loveprogrammer.lowercode.dna.instance.bo.Inst;
import com.loveprogrammer.lowercode.dna.common.CodeDefConst;
import com.loveprogrammer.lowercode.dna.instance.bo.Cell;
import com.loveprogrammer.lowercode.dna.service.InstServiceTemp;
import com.loveprogrammer.lowercode.dna.util.JsonUtils;

public class PartyInstController {

    private InstServiceTemp instService;

    public void createInst() throws JsonProcessingException {
        Inst partyInst = instService.init(CodeDefConst.INST_TYPE_DEFAULT,
                CodeDefConst.BUSINESS_TYPE_PARTY,CodeDefConst.DNA_CODE_PARTY);

        Cell partyCell = partyInst.getSingleCell();
        partyCell.setVaByName("partyName","张三");
        partyCell.setVaByName("certType","01");
        partyCell.setVaByName("certId","0030204569090");
        partyCell.setVaByName("certMobileNo","13813800001");

        Inst accoutInst = instService.init(CodeDefConst.INST_TYPE_DEFAULT,CodeDefConst.BUSINESS_TYPE_PARTY
                ,CodeDefConst.DNA_CODE_PARTY_ACCOUNT);
        Cell accountCell = accoutInst.getSingleCell();
        accountCell.setVaByName("accountName","张三");
        accountCell.setVaByName("accountNo","10001001001001");
        accountCell.setVaByName("bankName","中国银行");

        Inst anotherAccoutInst = instService.init(CodeDefConst.INST_TYPE_DEFAULT,CodeDefConst.BUSINESS_TYPE_PARTY
                ,CodeDefConst.DNA_CODE_PARTY_ACCOUNT);
        Cell anotherAccoutCell = anotherAccoutInst.getSingleCell();
        anotherAccoutCell.setVaByName("accountName","张三");
        anotherAccoutCell.setVaByName("accountNo","20002001001002");
        anotherAccoutCell.setVaByName("bankName","建设银行");

        accoutInst.addCell(anotherAccoutCell);

        partyCell.addChildInst(accoutInst.getDnaName(),accoutInst.getDnaCode(),accoutInst);

        System.out.println(JsonUtils.pojoToJson(partyInst));
    }

    public InstServiceTemp getInstService() {
        return instService;
    }

    public void setInstService(InstServiceTemp instService) {
        this.instService = instService;
    }

    public static void main(String[] args) throws JsonProcessingException {
        PartyInstController controller = new PartyInstController();
        controller.setInstService(new InstServiceTemp());
        controller.createInst();
    }
}
